{
  //声明函数
  function add(a: number, b: number): number {
    return a + b;
  }
  add(1, 2);

  let minus = function (a: number, b: number): number {
    return a - b;
  };

  minus(20, 10);

  //声明函数
  let times = (a: number, b: number) => {
    return a * b;
  }

  console.log(times(10, 20));

  //函数变量的类型
  let fn: (a: number, b: number) => number;
  fn = (a: number, b: number) => {
    return a + b;
  }

  // : 后边 = 前边的内容都是类型声明
  let fn2: (a:number, b: number) => number = (a: number, b: number): number => {
    return a + b;
  }

  //声明函数  str.slice(1)  str.slice(1, 5);
  // function slice(start: number, end ?: number){

  // }
  // slice(1, 5);
  // slice(1);

  function buildPhone(code: string, area: string='+86' ){
    return area + code
  }

  console.log(buildPhone('14856238954'));
  console.log(buildPhone('15896582547'));
  console.log(buildPhone('15896582569'));
  console.log(buildPhone('15896582578'));
  console.log(buildPhone('15896582578', '+123'));

  //rest 参数    push  unshift  splice
  function jia(...args: number[]){
    return args.reduce((prev, cur) => prev + cur);
  }
  console.log(jia(1,2,3,4,5));
  
}
